home *** CD-ROM | disk | FTP | other *** search
-
-
-
- MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM)))) MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
-
-
-
- NNNNAAAAMMMMEEEE
- matherr - error-handling function
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ####iiiinnnncccclllluuuuddddeeee <<<<mmmmaaaatttthhhh....hhhh>>>>
-
- iiiinnnntttt mmmmaaaatttthhhheeeerrrrrrrr ((((ssssttttrrrruuuucccctttt eeeexxxxcccceeeeppppttttiiiioooonnnn ****xxxx))));;;;
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- mmmmaaaatttthhhheeeerrrrrrrr is invoked by the following functions in libmx.a when errors are
- detected:
-
- acos acosf acosh asin asinf asinh atan atanf atan2 atan2f atanh cbrt cos
- cosf cosh coshf drem erf erfc
- exp expf expm1 expm1f fmod fmodf gamma hypot hypotf j0 j1 jn lgamma log
- logf log10 log10f log1p log1pf
- pow powf sin sinf sinh sinhf sqrt sqrtf tan tanf tanh tanhf y0 y1 yn
-
- Note that to use mmmmaaaatttthhhheeeerrrrrrrr, libmx.a needs to be linked with the program.
- Users may define their own routines for handling errors by including a
- function named mmmmaaaatttthhhheeeerrrrrrrr in their programs. mmmmaaaatttthhhheeeerrrrrrrr must be of the form
- described above. When an error occurs, a pointer to the exception
- structure _x will be passed to the user-supplied mmmmaaaatttthhhheeeerrrrrrrr function. This
- structure, which is defined in the _m_a_t_h._h header file, is as follows:
-
- struct exception {
- int type;
- char *name;
- double arg1, arg2, retval;
- };
-
- The element _t_y_p_e is an integer describing the type of error that has
- occurred, from the following list of constants (defined in the header
- file math.h):
-
- DOMAIN argument domain error
- SING argument singularity
- OVERFLOW overflow range error
- UNDERFLOW underflow range error
- TLOSS total loss of significance
- PLOSS partial loss of significance
-
- The element _n_a_m_e points to a string containing the name of the function
- that incurred the error. The elements _a_r_g_1 and _a_r_g_2 are the arguments
- with which the function was invoked. _r_e_t_v_a_l is set to the default value
- that will be returned by the function unless the user's mmmmaaaatttthhhheeeerrrrrrrr sets it
- to a different value.
-
- NaN argument(s) to any of the above functions generates a call to matherr
- with a domain error.
-
-
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM)))) MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
-
-
-
- If the user's mmmmaaaatttthhhheeeerrrrrrrr function returns non-zero, no error message will be
- printed by the calling function, and _e_r_r_n_o will not be set.
-
- If mmmmaaaatttthhhheeeerrrrrrrr is not supplied by the user, the default error-handling
- procedures, described by the table below, will be invoked upon error. In
- every case, _e_r_r_n_o is set to EDOM or ERANGE and the program continues.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-
-
-
- MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM)))) MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
-
-
-
- _______________________________________________________________________________
- Default Error Handling Procedures
- ______________________________________________________________________________
- Types of Errors
- ______________________________________________________________________________
- type DOMAIN SING OVERFLOW UNDERFLOW TLOSS PLOSS
- ______________________________________________________________________________
- errno EDOM EDOM ERANGE ERANGE ERANGE ERANGE
- ______________________________________________________________________________
- EXP, EXPF: - - M, H M, 0 - -
- ______________________________________________________________________________
- EXPM1, EXPM1F: - - M, H M, 0 - -
- ______________________________________________________________________________
- LOG, LOGF:
- LOG10, LOG10F:
- (arg < 0) M, N - - - - -
- (arg = 0) M, -H - - - - -
- ______________________________________________________________________________
- LOG1P, LOG1PF:
- (arg < -1) M, N - - - - -
- (arg = -1) M, -H - - - - -
- ______________________________________________________________________________
- POW, POWF: - - +_H 0 - -
- neg ** non-int M, 0 - - - - -
- 0 ** non-pos M, H - - - - -
- ______________________________________________________________________________
- SQRT, SQRTF: M, N - - - - -
- ______________________________________________________________________________
- DREM, FMOD, FMODF:
- (arg1 = +/-inf M, N - - - - -
- or arg2 = 0)
- ______________________________________________________________________________
- GAMMA, LGAMMA: - M, H M, H - - -
- ______________________________________________________________________________
- J0, J1, JN: - - - - M, 0 -
- ______________________________________________________________________________
- Y0, Y1, YN:
- (arg = 0) - - M, -H - - -
- (arg < 0) M, N - - - - -
- (arg >= 2**49) - - - - M, 0 -
- ______________________________________________________________________________
- SINH, SINHF: - - +_H - - -
- ______________________________________________________________________________
- COSH, COSHF: - - H - - -
- ______________________________________________________________________________
- HYPOT, HYPOTF: - - M, H - - -
- ______________________________________________________________________________
- ASIN, ASINF:
- ACOS, ACOSF: M, N - - - - -
- ______________________________________________________________________________
- ______________________________________________________________________________
- ||||||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ||||||||||||||||||||||||||||||||||||||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 3333
-
-
-
-
-
-
- MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM)))) MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
-
-
-
- SIN, COS, TAN:
- (arg >= 2**50) M, N - - - - -
- (arg = +/-inf) - - - - M, 0 -
- ______________________________________________________________________________
- SINF, COSF, TANF:
- (arg >= 2**22) M, N - - - - -
- (arg = +/-inf) - - - - M, 0 -
- ______________________________________________________________________________
- ATAN2, ATAN2F: M, 0 - - - - -
- ______________________________________________________________________________
- ACOSH: M, N - - - - -
- ______________________________________________________________________________
- ATANH:
- (|arg| > 1) M, N - - - - -
- ______________________________________________________________________________
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
- |||||||||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ______________________________________________________________________________
- Abbreviations
- M Message is printed
- H HUGE is returned
- -H -HUGE is returned
- +_H HUGE or -HUGE is returned.
- 0 0 is returned.
- X _a_r_g_1 is returned.
- N NaN is returned.
- ______________________________________________________________________________
- |||||||||
-
-
-
-
-
-
-
- |||||||||
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 4444
-
-
-
-
-
-
- MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM)))) MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
-
-
-
- EEEEXXXXAAAAMMMMPPPPLLLLEEEE
- /*
- ** Example showing the use of libmx.a's matherr() to handle math errors.
- **
- ** % cc -xansi my_matherr.c -lmx
- ** % a.out
- ** overflow range error in logf
- ** logf(0.0) is -inf.
- **
- ** expf failed: Argument out of domain
- ** Abort (core dumped)
- */
-
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
-
- main()
- {
- float ff;
-
- ff = logf(0.0f); /* matherr() leaves error reporting to libmx.a */
- printf("logf(0.0f) is %f.\n\n",ff);
- fflush(stdout);
-
- ff = 0.0f;
- ff = 0.0f/ff;
- ff = expf(ff); /* matherr() customized to force a core dump */
- }
-
- int matherr( register struct exception *x )
- {
- char *sterr;
-
- switch (x->type) {
-
- case DOMAIN:
- /* if it's a NaN, abort */
-
- if ( isnan(x->arg1) )
- {
- sterr = strerror(EDOM);
- fprintf(stderr, "%s failed: %s\n", x->name, sterr);
- abort();
- }
- else if ( !strcmp(x->name, "sin") )
- {
- x->retval = 0.0; /* return 0.0 */
- fprintf(stderr, "domain error in sin\n");
-
-
-
-
- PPPPaaaaggggeeee 5555
-
-
-
-
-
-
- MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM)))) MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
-
-
-
- return (1); /* suppress libmx.a error message and setting of errno */
- }
- else
- return (0); /* libmx.a prints error message and sets errno */
- break;
-
- default:
- return (0); /* libmx.a prints error message and sets errno */
- }
- }
-
- NNNNOOOOTTTTEEEESSSS
- Errors detected by functions in libm.a can be detected by examining the
- return value and/or the global variable _e_r_r_n_o. libmx.a is provided as an
- alternative error handling scheme for users who want to identify specific
- kinds of errors determined by libm functions without extensive
- modification of their source code.
-
- No extra overhead is incurred by programs using libmx.a if no error
- conditions are encountered in the libmx routines.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 6666
-
-
-
-